﻿using System;
using System.Collections.Generic;
using System.Text;
using rkShared.Net;
using rkShared.BEncode;

namespace rkServer
{
    public class ChatServer
    {
        private GameServer m_server;
        public event MessageReceivedEventHandler ChatMessageReceived;

        public ChatServer(GameServer server)
        {
            m_server = server;
            m_server.ClientRegistered += new ClientRegisteredEventHandler(m_server_ClientRegistered);
            m_server.ChatMessageReceived += new MessageReceivedEventHandler(m_server_ChatMessageReceived);
        }
        void m_server_ChatMessageReceived(ClientInfo client, NetMessage msg)
        {
            //diger clientlara gonder....
            //(msg.Data as BEncodedString).ValueStr;
            if (this.ChatMessageReceived != null)
                this.ChatMessageReceived(null, msg);

            if (m_server.Clients.Count > 1)
            {
                foreach (ClientInfo c in m_server.Clients)
                {
                    if (c.ClientID != client.ClientID)
                    {
                        m_server.SendTcpMessage(c, msg);
                    }
                }
            } 

        }
        void m_server_ClientRegistered(rkShared.Net.ClientInfo cliInfo)
        {

        }
    }
}
